#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    // 请在此输入您的代码
    int N, V;
    cin >> N >> V;
    vector<int> w(N + 1), v(N + 1);
    for (int i = 1;i <= N;i++)
    {
        cin >> w[i] >> v[i];
    }
    vector<int> dp(V + 1, 0);
    for (int i = 1;i <= N;i++)
    {
        for (int j = w[i];j <= V;j++)
        {
            dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
        }
    }
    cout << dp[V];
    return 0;
}